home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / AMesaRTL.lha / Mesa-2.6 / amiga / src-glut / glutstuff.c < prev    next >
C/C++ Source or Header  |  1998-09-19  |  5KB  |  296 lines

  1. /*
  2.  * Amiga GLUT graphics library toolkit
  3.  * Version:  2.0
  4.  * Copyright (C) 1998 Jarno van der Linden
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Library General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Library General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public
  17.  * License along with this library; if not, write to the Free
  18.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21.  
  22. /*
  23.  * glutstuff.c
  24.  *
  25.  * Version 1.0  27 Jun 1998
  26.  * by Jarno van der Linden
  27.  * jarno@kcbbs.gen.nz
  28.  *
  29.  * Version 1.1  02 Aug 1998
  30.  * by Jarno van der Linden
  31.  * jarno@kcbbs.gen.nz
  32.  *
  33.  * - Quantizer plugin support added
  34.  *
  35.  * Version 2.0  19 Sep 1998
  36.  * by Jarno van der Linden
  37.  * jarno@kcbbs.gen.nz
  38.  *
  39.  * - Added glutAssociateGL() to get hold of mesa bases
  40.  * - Changed to runtime library format
  41.  * - Changed quantizer to output handler
  42.  * - Added handlerwindow flag
  43.  *
  44.  */
  45.  
  46.  
  47. #include <constructor.h>
  48.  
  49. #include <proto/exec.h>
  50.  
  51. #include "glutstuff.h"
  52.  
  53.  
  54. struct GlutStuff glutstuff;
  55. struct Library *mesamainBase = NULL;
  56. struct Library *mesadriverBase = NULL;
  57.  
  58.  
  59. DEFAULT_CONSTRUCTOR(glutConstruct)
  60. {
  61.     glutstuff.msgport = CreateMsgPort();
  62.     if(glutstuff.msgport == NULL)
  63.     {
  64.         return(1);
  65.     }
  66.     glutstuff.curwin = NULL;
  67.     glutstuff.wins = NULL;
  68.     glutstuff.nextwinid = 1;
  69.  
  70.     glutstuff.curmenu = NULL;
  71.     glutstuff.menus = NULL;
  72.     glutstuff.nextmenuid = 1;
  73.  
  74.     glutstuff.initposx = -1;
  75.     glutstuff.initposy = -1;
  76.     glutstuff.initwidth = 300;
  77.     glutstuff.initheight = 300;
  78.  
  79.     glutstuff.numcolours = 248;
  80.     glutstuff.colourbase = 8;
  81.     glutstuff.pubscreenname = "Mesa";
  82.     glutstuff.oh = NULL;
  83.     glutstuff.ohversion = -1;
  84.  
  85.     glutstuff.handlerwindow = TRUE;
  86.  
  87.     glutstuff.rgba = GL_TRUE;
  88.     glutstuff.alpha = GL_FALSE;
  89.     glutstuff.db = GL_FALSE;
  90.     glutstuff.accum = GL_FALSE;
  91.     glutstuff.depth = GL_FALSE;
  92.     glutstuff.stencil = GL_FALSE;
  93.     glutstuff.multisample = GL_FALSE;
  94.     glutstuff.stereo = GL_FALSE;
  95.     glutstuff.luminance = GL_FALSE;
  96.  
  97.     glutstuff.idlefunc = NULL;
  98.     glutstuff.menustatusfunc = NULL;
  99.  
  100.     glutstuff.basetime_secs = 0;
  101.     glutstuff.basetime_micros = 0;
  102.     glutstuff.havebasetime = FALSE;
  103.  
  104.     return(0);
  105. }
  106.  
  107.  
  108. DEFAULT_DESTRUCTOR(glutDestruct)
  109. {
  110.     struct GlutWindow *gw, *gwn;
  111.     struct GlutMenu *gm, *gmn;
  112.  
  113.     gw = glutstuff.wins;
  114.     while(gw)
  115.     {
  116.         gwn = gw->next;
  117.         glutDestroyWindow(gw->winid);
  118.         gw = gwn;
  119.     }
  120.  
  121.     gm = glutstuff.menus;
  122.     while(gm)
  123.     {
  124.         gmn = gm->next;
  125.         glutDestroyMenu(gm->menuid);
  126.         gm = gmn;
  127.     }
  128.  
  129.     if(glutstuff.msgport)
  130.         DeleteMsgPort(glutstuff.msgport);
  131. }
  132.  
  133.  
  134. int stuffGetNewWinID(void)
  135. {
  136.     return(glutstuff.nextwinid++);
  137. }
  138.  
  139.  
  140. struct GlutWindow *stuffGetWin(int winid)
  141. {
  142.     struct GlutWindow *gw;
  143.  
  144.     gw = glutstuff.wins;
  145.     while(gw && (gw->winid != winid))
  146.         gw = gw->next;
  147.  
  148.     return(gw);
  149. }
  150.  
  151.  
  152. void stuffLinkInWin(struct GlutWindow *gw)
  153. {
  154.     gw->next = glutstuff.wins;
  155.     gw->prev = NULL;
  156.     if(glutstuff.wins)
  157.         glutstuff.wins->prev = gw;
  158.     glutstuff.wins = gw;
  159.  
  160.     stuffMakeCurrent(gw);
  161. }
  162.  
  163.  
  164. void stuffLinkOutWin(struct GlutWindow *gw)
  165. {
  166.     if(gw->prev)
  167.         gw->prev->next = gw->next;
  168.     if(gw->next)
  169.         gw->next->prev = gw->prev;
  170.  
  171.     if(glutstuff.wins == gw)
  172.         glutstuff.wins = gw->next;
  173.  
  174.     if(glutstuff.curwin == gw)
  175.         glutstuff.curwin = NULL;
  176. }
  177.  
  178.  
  179. void stuffMakeCurrent(struct GlutWindow *gw)
  180. {
  181.     if(glutstuff.curwin != gw)
  182.     {
  183.         glutstuff.curwin = gw;
  184.  
  185.         AmigaMesaRTLMakeCurrent(gw->context);
  186.     }
  187. }
  188.  
  189.  
  190. int stuffGetNewMenuID(void)
  191. {
  192.     return(glutstuff.nextmenuid++);
  193. }
  194.  
  195.  
  196. struct GlutMenu *stuffGetMenu(int menuid)
  197. {
  198.     struct GlutMenu *gm;
  199.  
  200.     gm = glutstuff.menus;
  201.     while(gm && (gm->menuid != menuid))
  202.         gm = gm->next;
  203.  
  204.     return(gm);
  205. }
  206.  
  207.  
  208. void stuffLinkInMenu(struct GlutMenu *gm)
  209. {
  210.     gm->next = glutstuff.menus;
  211.     gm->prev = NULL;
  212.     if(glutstuff.menus)
  213.         glutstuff.menus->prev = gm;
  214.     glutstuff.menus = gm;
  215.  
  216.     stuffMakeCurrentMenu(gm);
  217. }
  218.  
  219.  
  220. void stuffLinkOutMenu(struct GlutMenu *gm)
  221. {
  222.     if(gm->prev)
  223.         gm->prev->next = gm->next;
  224.     if(gm->next)
  225.         gm->next->prev = gm->prev;
  226.  
  227.     if(glutstuff.menus == gm)
  228.         glutstuff.menus = gm->next;
  229.  
  230.     if(glutstuff.curmenu == gm)
  231.         glutstuff.curmenu = NULL;
  232. }
  233.  
  234.  
  235. void stuffMakeCurrentMenu(struct GlutMenu *gm)
  236. {
  237.     if(glutstuff.curmenu != gm)
  238.     {
  239.         glutstuff.curmenu = gm;
  240.     }
  241. }
  242.  
  243.  
  244. struct GlutMenuEntry *stuffGetMenuEntry(int entry,struct GlutMenu *gm)
  245. {
  246.     struct GlutMenuEntry *gme;
  247.  
  248.     gme = gm->entries;
  249.     entry--;
  250.  
  251.     for(;entry > 0; entry--)
  252.         gme = gme->next;
  253.  
  254.     return(gme);
  255. }
  256.  
  257.  
  258. void stuffLinkInMenuEntry(struct GlutMenuEntry *gme,struct GlutMenu *gm)
  259. {
  260.     struct GlutMenuEntry *p;
  261.  
  262.     for(p=gm->entries; p && p->next; p=p->next)
  263.         ;
  264.     gme->next = NULL;
  265.     gme->prev = p;
  266.     if(p)
  267.         p->next = gme;
  268.     else
  269.         gm->entries = gme;
  270.     gm->numentries++;
  271.     gme->menu = gm;
  272. }
  273.  
  274.  
  275. void stuffLinkOutMenuEntry(struct GlutMenuEntry *gme,struct GlutMenu *gm)
  276. {
  277.     if(gme->prev)
  278.         gme->prev->next = gme->next;
  279.     if(gme->next)
  280.         gme->next->prev = gme->prev;
  281.  
  282.     if(gm->entries == gme)
  283.         gm->entries = gme->next;
  284.  
  285.     gm->numentries--;
  286.  
  287.     gme->menu = NULL;
  288. }
  289.  
  290.  
  291. __asm __saveds void glutAssociateGL(register __a0 struct Library *mesamainBaseArg, register __a1 struct Library *mesadriverBaseArg)
  292. {
  293.     mesamainBase = mesamainBaseArg;
  294.     mesadriverBase = mesadriverBaseArg;
  295. }
  296.